/*
 * Created on Feb 20, 2007
 */
package sandboxmv.executable;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.Timer;

import sandboxmv.gamedata.ControlledHero;
import sandboxmv.gamedata.GameData;
import sandboxmv.panels.GameDisplayPanel;

/**
 * @author Zach Toups (toupsz@gmail.com)
 */
public class SinglePlayerExec implements ActionListener
{
    private GameData gd;
    private ControlledHero h;
    
    private JFrame f;
    
        /**
     * @param args
     */
    public static void main(String[] args)
    {
        GameData gd = new GameData();
        ControlledHero h = new ControlledHero(100, 0, 250, "Zach", 0, gd, "A1");

        SinglePlayerExec exec = new SinglePlayerExec(gd, h);
    }

    public SinglePlayerExec(GameData gd, ControlledHero h)
    {
        this.gd = gd;
        this.h = h;
        
        f = new JFrame();
        f.setSize(new Dimension(600, 600));
        f.getContentPane().add(new GameDisplayPanel(600, 600, h, gd));
        f.addKeyListener(h);
        f.requestFocus();
        
        JFrame.setDefaultLookAndFeelDecorated(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setLocation(300, 10);
        f.pack();
        f.setVisible(true);

        Timer t = new Timer(33, this);
        t.start();
    }
    
    public void actionPerformed(ActionEvent arg0)
    {
        h.update();
        gd.runGameCycle();
        
        f.repaint();
    }

}
